package com.chenyaowei.happyhub.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;

import com.tencentcloudapi.captcha.v20190722.CaptchaClient;
import com.tencentcloudapi.captcha.v20190722.models.*;;
@Service
public class CaptchaService {
    @Value("${captcha.SecretId}")
    private  String secretId;
    @Value("${captcha.SecretKey}")
    private  String secretKey;
    @Value("${captcha.AppId}")
    private long appId;
    @Value("${captcha.AppSecretKey}")
    private String appSecretKey;
    private long captchaType=9L;
    private String userIp="10.61.152.75";
    private  String VERIFY_URL = "captcha.tencentcloudapi.com";

    boolean VerifyTicket(String ticket, String randStr){
        try{
            Credential cred = new Credential(secretId, secretKey);
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint(VERIFY_URL);
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            CaptchaClient client = new CaptchaClient(cred, "", clientProfile);
            DescribeCaptchaResultRequest req = new DescribeCaptchaResultRequest();
            req.setTicket(ticket);
            req.setRandstr(randStr);
            req.setUserIp(userIp);
            req.setCaptchaAppId(appId);
            req.setAppSecretKey(appSecretKey);
            req.setCaptchaType(captchaType);
            DescribeCaptchaResultResponse resp = client.DescribeCaptchaResult(req);
            System.out.println(DescribeCaptchaResultResponse.toJsonString(resp));
            System.out.println(resp);
        } catch (TencentCloudSDKException e) {
            System.out.println(e.toString());
            return false;
        }
        return true;
    }
}
